//显示该产品的评论数
var customerId =  $(".customerid").val();
console.log("用户id："+customerId)

getCount();
function getCount() {
    var productId =  $(".productid").val();
    console.log(productId);
    console.log("测试");
    $.ajax({
        type:"GET",
        url:"/fresh/comment/getCount/"+productId,
        dataType:"json",
        success:function (result) {
            if (result.status==1){
                console.log("查询成功1");
                var count = result.data;
                $("#get-count").html("");
                var str = "";
                str = result.data;
                $("#get-count").html(str);
            }else {
                console.log("没有得到用户的评论数");
            }
        }
    })
}

//显示用户所有的评论
getAllComment();
function getAllComment() {
    var productId = $(".productid").val();
    console.log(productId);
    $.ajax({
        type:"GET",
        url:"/fresh/comment/getAll/"+productId,
        dataType:"json",
        success:function (result) {
            if (result.status ==1){
                console.log("查询成功2");
                $(".comment-ul").html("");
                var str = "";
                $.each(result.data,function (index,commentList) {
                    var commentId = commentList.comment.commentId;
                    var customerId = commentList.comment.customerId;
                    var commentsStars = commentList.comment.commentsStars;
                    var commentContent = commentList.comment.commentContent;
                    var commentTime = commentList.comment.commentTime;

                    var customerName = commentList.customer.customerName;
                    var customerTelno = commentList.customer.customerTelno;

                    var ele = " <li>\n" +
                        "\n" +
                        "                       <div class=\"content-comment\">\n" +
                        "                           <div class=\"heading\">\n" +
                        "                               <div class=\"stars-pg\">\n" +
                        "<!--                                   <span style=\"width: 60%\"></span>-->\n" +
                        "                               </div>\n" +
                        "                               <div class=\"pingfen\">\n" +
                        "                                   <span class=\"c-star\">"+commentsStars+"</span>\n" +
                        "                                   <span>分</span>\n" +
                        "                               </div>\n" +
                        "\n" +
                        "                               <div class=\"date\">\n" +
                        "                                   <span class=\"c-time\">"+commentTime+"</span>\n" +
                        "                               </div>\n" +
                        "\n" +
                        "                           </div>\n" +
                        "                           <div class=\"reply\">\n" +
                        "                               <span class=\"c-content\">"+commentContent+"</span>\n" +
                        "\n" +
                        "                           </div>\n" +
                        "                       </div>\n" +
                        "                   </li>"

                    str +=ele;

                })
                $(".comment-ul").html(str);
            }else {
                console.log("未查询到数据")
            }
        }
    })
}

//数量加减
$(".reduce").click(function () {
    var count = $(".count").text()
    if (count == 1)
        $(".reduce").attr("disable","true")
    else{
        count = parseInt(count)-1;
        $(".count").text(count)
    }
})
$(".addcount").click(function () {
    var count = $(".count").text()
    $(".count").text(parseInt(count)+1)
})
//跳转到购物车
/*$(".add-car").click(function () {
    var productId = $(".productid").val();
    $.ajax({
        type: "post",
        url: "/fresh/product/addcart",
        data: "productId=" + productId,
        dataType: "json",
        success:function (result) {
            console.log(result)

        }
    })
})*/


//将商品加入购物车
$(".add-product").click(function () {
    var productId = $(".productid").val();
    var customerId = $(".customerid").val();
    $.ajax({
        type: "get",
        url: "/fresh/cart/add/"+customerId+"/"+productId,

        dataType: "json",
        success:function (result) {
            console.log(result);
            if (result.status==1){
                console.log("商品加入购物车");
                alert("商品加入购物车");
            }else {
                console.log("商品加入购物车失败");
            }
        }
    })
})

